<template>
  <view class="wallet">
    <header-vue :back="true" :title="title" bgColor="transparent"></header-vue>
    <view class="background-gradient">
      <image
        :src="IMAGE_URL+'/static/master/qianbao.png'"
        style="width: 100%; height: 640rpx"
      />
    </view>
    <view class="wallet-content">
      <!-- 余额卡片 -->
      <view class="balance-card">
        <view class="balance-header">
          <view class="balance-amount">
            <text class="balance-amount-money">￥</text>
            {{ walletData.balance }}
          </view>
          <view class="action-buttons">
            <button class="recharge-btn" @click="handleRecharge">充值</button>
            <button class="withdraw-btn" @click="handleWithdraw">提现</button>
          </view>
        </view>
      </view>

      <view class="records-card">
        <!-- 记录选项卡 -->
        <view class="tabs-section">
          <view class="tabs">
            <view
              class="tab-item"
              :class="{ active: activeTab === 'recharge' }"
              @click="switchTab('recharge')"
            >
              <text>充值记录</text>
            </view>
            <view
              class="tab-item"
              :class="{ active: activeTab === 'withdraw' }"
              @click="switchTab('withdraw')"
            >
              <text>提现记录</text>
            </view>
            <view
              class="tab-item"
              :class="{ active: activeTab === 'consume' }"
              @click="switchTab('consume')"
            >
              <text>消费记录</text>
            </view>
          </view>
        </view>

        <!-- 记录列表 -->
        <view class="records-section">
          <!-- 充值记录 -->
          <view v-if="activeTab === 'recharge'" class="recharge-records">
            <view
              v-for="(record, index) in rechargeRecords"
              :key="index"
              class="record-item"
            >
              <view class="record-left">
                <view class="record-info">
                  <text class="record-type">{{ record.type }}</text>
                  <text class="record-time">{{ record.time }}</text>
                </view>
              </view>
              <view class="record-right">
                <text class="record-amount">+{{ record.amount }}</text>
              </view>
            </view>
          </view>

          <!-- 提现记录 -->
          <view v-if="activeTab === 'withdraw'" class="withdraw-records">
            <view
              v-for="(record, index) in withdrawRecords"
              :key="index"
              class="record-item"
            >
              <view class="record-left">
               
                <view class="record-info">
                  <text class="record-type">{{ record.type }}</text>
                  <text class="record-time">{{ record.time }}</text>
                </view>
              </view>
              <view class="record-right">
                <text class="record-amount withdraw-amount"
                  >-{{ record.amount }}</text
                >
              </view>
            </view>
          </view>

          <!-- 消费记录 -->
          <view v-if="activeTab === 'consume'" class="consume-records">
            <view
              v-for="(record, index) in consumeRecords"
              :key="index"
              class="record-item"
            >
              <view class="record-left">
             
                <view class="record-info">
                  <text class="record-type">{{ record.type }}</text>
                  <text class="record-time">{{ record.time }}</text>
                </view>
              </view>
              <view class="record-right">
                <text class="record-amount consume-amount"
                  >-{{ record.amount }}</text
                >
              </view>
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import headerVue from "@/components/header.vue";
import appConfig from "@/config/app.js";
//  IMAGE_URL: appConfig.IMAGE_URL,
export default {
  data() {
    return {
      IMAGE_URL: appConfig.IMAGE_URL,
      title: "我的余额",
      activeTab: "recharge",
      walletData: {
        balance: "250.00",
      },
      rechargeRecords: [
        {
          type: "微信充值",
          time: "2025-04-06 15:45",
          amount: "36",
          icon: "/static/images/wechat-icon.png",
        },
        {
          type: "银行卡充值",
          time: "2025-04-06 15:45",
          amount: "36",
          icon: "/static/images/bank-icon.png",
        },
        {
          type: "支付宝充值",
          time: "2025-04-06 15:45",
          amount: "36",
          icon: "/static/images/alipay-icon.png",
        },
        {
          type: "佣金充值",
          time: "2025-04-06 15:45",
          amount: "36",
          icon: "/static/images/commission-icon.png",
        },
        {
          type: "微信充值",
          time: "2025-04-06 15:45",
          amount: "36",
          icon: "/static/images/wechat-icon.png",
        },
      ],
      withdrawRecords: [
        {
          type: "微信提现",
          time: "2025-04-05 10:30",
          amount: "100",
          icon: "/static/images/wechat-icon.png",
        },
        {
          type: "银行卡提现",
          time: "2025-04-04 14:20",
          amount: "200",
          icon: "/static/images/bank-icon.png",
        },
      ],
      consumeRecords: [
        {
          type: "服务消费",
          time: "2025-04-06 15:45",
          amount: "50",
          icon: "/static/images/consume-icon.png",
        },
        {
          type: "商品购买",
          time: "2025-04-05 09:15",
          amount: "80",
          icon: "/static/images/shop-icon.png",
        },
      ],
    };
  },
  components: {
    headerVue,
  },
  methods: {
    // 切换选项卡
    switchTab(tab) {
      this.activeTab = tab;
    },

    // 处理充值
    handleRecharge() {
      uni.navigateTo({
        url: "/views-master/my/top-up",
      });
    },

    // 处理提现
    handleWithdraw() {
      uni.navigateTo({
        url: "/views-master/my/withdraw",
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.wallet {
  height: 100vh;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  width: 100%;
  overflow: hidden;
  position: relative;
  background: #f7f7f7;

  .background-gradient {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 0;
  }

  .wallet-content {
    flex: 1;
    box-sizing: border-box;
    width: 100%;
    overflow-y: auto;
    position: relative;
    z-index: 1;
    padding: 50rpx 32rpx 32rpx;
  }

  .balance-card {
   
  }

  .balance-title {
    font-size: 28rpx;
    color: #666666;
    font-weight: 400;
    margin-bottom: 20rpx;
    text-align: center;
  }

  .balance-header {
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .balance-amount {
    font-size: 48rpx;
    color: #333333;
    font-weight: bold;
    margin-bottom: 30rpx;
  }

  .balance-amount-money {
    font-size: 36rpx;
  }

  .action-buttons {
    display: flex;
    gap: 30rpx;
    justify-content: center;
    width: 100%;
    margin-bottom: 60rpx;
  }

  .recharge-btn {
    border: none;

    font-size: 32rpx;
    color: #ffffff;
    width: 202rpx;
    height: 68rpx;
    line-height: 68rpx;
    background: #df9824;
    border-radius: 100rpx 100rpx 100rpx 100rpx;

    &::after {
      border: none;
    }
  }

  .withdraw-btn {
    border: none;

    font-size: 32rpx;
    color: #ffffff;
    width: 202rpx;
    height: 68rpx;
    line-height: 68rpx;
    background: #149ceb;
    border-radius: 100rpx 100rpx 100rpx 100rpx;

    &::after {
      border: none;
    }
  }

  .tabs-section {
    margin-bottom: 32rpx;
  }

  .records-card {
    background: #ffffff;
    box-shadow: 0rpx 4rpx 20rpx 0rpx rgba(0, 0, 0, 0.1);
    border-radius: 20rpx 20rpx 0 20rpx;
  }

  .tabs {
    display: flex;
  }

  .tab-item {
    flex: 1;
    text-align: center;
    padding: 28rpx 0 10rpx 0;
    font-size: 28rpx;
    color: #666666;
    position: relative;

    &.active {
      color: #333;
      font-weight: 600;
      font-size: 30rpx;

      &::after {
        content: "";
        position: absolute;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 60rpx;
        height: 4rpx;

        background: #149ceb;
        border-radius: 2rpx;
      }
    }
  }

  .records-section {
    background: #ffffff;
    border-radius: 0 0 16rpx 16rpx;
    padding: 0 30rpx;
    flex: 1;
    min-height: 300rpx;
  }

  .record-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20rpx 0;
  }

  .record-left {
    display: flex;
    align-items: center;
    flex: 1;
  }

  .record-icon {
    width: 60rpx;
    height: 60rpx;
    margin-right: 20rpx;
    background: #f8f9fa;
    border-radius: 8rpx;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .icon-img {
    width: 40rpx;
    height: 40rpx;
  }

  .record-info {
    display: flex;
    flex-direction: column;
  }

  .record-type {
    font-size: 28rpx;
    color: #333333;
    font-weight: 500;
    margin-bottom: 5rpx;
  }

  .record-time {
    font-size: 24rpx;
    color: #999999;
  }

  .record-right {
    display: flex;
    align-items: center;
  }

  .record-amount {
    font-size: 30rpx;
    font-weight: 600;
    color: #52c41a;

    &.withdraw-amount,
    &.consume-amount {
      color: #e74c3c;
    }
  }
}
</style>
